package cn.hotel.controller.worker;

import cn.hotel.entity.RoomType;
import cn.hotel.response.ResponseTool;
import cn.hotel.response.Result;
import cn.hotel.service.RoomTypeService;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
@RequestMapping(value = "/op/room-type")
public class OpRoomTypeController {
    @Resource
    private RoomTypeService roomTypeService;

    /**
     * 用于添加房间信息的时候使用
     * @return
     */
    @PostMapping ()
    public Result getAllRoomTypes(){
        List<RoomType> roomTypes = roomTypeService.queryAllRoomType();
        log.info("roomTypes=={}",roomTypes);
        return ResponseTool.success(roomTypes);
    }

    /**
     * 分页查询
     * 获取所有的房间类别信息
     * @return
     */
    @PostMapping("/list")
    public Result getAllRoomTypes(Integer page , Integer pageSize){
        log.info("page:{}" , page);
        log.info("pageSize:{}" , pageSize);
        PageInfo<RoomType> pageInfo = roomTypeService.queryList(page, pageSize);
        return ResponseTool.success(pageInfo);
    }

    /**
     * 根据房间类别id查询房间类别信息
     * @param typeId
     * @return
     */
    @PostMapping("/{typeId}")
    public Result getRoomTypeByRoomTypeId(@PathVariable("typeId") int typeId){
        RoomType roomType = roomTypeService.queryRoomTypeByRoomTypeId(typeId);
        return ResponseTool.success(roomType);
    }

    /**
     * 更新房间类别信息
     * @param roomType
     * @return
     */
    @PostMapping("/update")
    public Result updateRoomType(RoomType roomType){
        log.info("roomType:{}",roomType);
        //执行更新操作
        roomTypeService.updateRoomType(roomType);
        return ResponseTool.success("更新成功");
    }

    /**
     * 插入房间的类型信息
     * @param roomType
     * @return
     */
    @PostMapping("/add")
    public Result addRoomType(RoomType roomType){
        log.info("roomType:{}",roomType);
        roomTypeService.insertRoomType(roomType);
        return ResponseTool.success("添加成功");
    }

    //删除房间类别信息
    @DeleteMapping("/delete")
    public Result deleteRoomTypeByIds(@RequestParam("typeIds")  List<Integer> typeIds){
        log.info("roomTypes:{}" , typeIds);
        for (Integer typeId : typeIds) {
            roomTypeService.deleteRoomTypeByRoomId(typeId);
        }
        return ResponseTool.success("删除成功");
    }
}
